package com.zhaowu.utils;

import javax.swing.*;
import java.awt.*;

public class LocationUtils {
    /**
     * 使得窗口居中 且让窗口大小为整个屏幕的一半
     * @param c
     */
    public static void center(Component c) {
        Toolkit kit = Toolkit.getDefaultToolkit();
        int width = kit.getScreenSize().width;
        int height = kit.getScreenSize().height;
        c.setSize(width/2, height/2);
        int x = ( width - c.getWidth()) / 2;
        int y = (height - c.getHeight()) / 2;
        c.setLocation(x, y);
    }
    public static void addJSeparator(Frame frame){
        JSeparator jSeparator = new JSeparator();
        jSeparator.setBackground(new Color(0xbb,0xbb,0xbb));
        frame.add(jSeparator);
    }

    public static void addFlowLayout(Frame frame){
        Panel panel = new Panel();
        panel.setSize(100,100);
        panel.setBackground(Color.darkGray);
        FlowLayout layout = new FlowLayout();
        panel.setLayout(layout);
        panel.add(new Button("OK"));
        panel.add(new Button("Cancel"));

        frame.add(panel);
    }
}
